$(function(){
	$("#loginName").attr('value','')
	$("#loginPwd").attr('value','')
})

//监控enter键
function enter_login(){
	if(event.keyCode == 13){
		login();
		event.returnValue = false;
	}
}

//登录
function login(){
	var name = $("#loginName").val();
	var pwd = $("#loginPwd").val();
	
	if(name == ""){
		$("#loginName").css("border","1px solid red");
		$("#nError").css("display","block");
		$("#nOk").css("display","none");
	}else{
		$("#loginName").css("border","");
		$("#nOk").css("display","block");
		$("#nError").css("display","none");
	}
	
	if(pwd == ""){
		$("#loginPwd").css("border","1px solid red");
		$("#pError").css("display","block");
		$("#pOk").css("display","none");
	}else{
		$("#loginPwd").css("border","");
		$("#pOk").css("display","block");
		$("#pError").css("display","none");
	}
	
	if(name != "" && pwd != ""){
		//账号或密码错误！登录失败！
		$.ajax({
			type: "post",
			data: {"account_name":name, "account_password":pwd},
			url: "login_on",
			beforeSend: function(){
				$("#load").css("display","block");
			},
			success: function(data){
				console.log(data);
				$("#load").css("display","none");
				if(data.errno == "0"){
					location.href=data.route;
				}else{
					$("#loginError").html(data.msg);
				}
			}
		});
	}
}
